/*
 * @lc app=leetcode.cn id=206 lang=java
 *
 * [206] 反转链表
 */

// @lc code=start
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode reverseList(ListNode head) {
        if ( head == null){
            return head;
        }
        ListNode last = head;
        ListNode temp;
        while ( last.next != null){
            last = last.next;
        }
        temp = last;
        while ( temp != head){
            ListNode temp1 = head;
            while (temp1.next != temp){
                temp1 = temp1.next;
            }
            temp.next = temp1;
            temp = temp.next;
        }
        temp.next = null;
        return last;
    }
    
}
// @lc code=end

